package com.lq.ecoldchain.ui.login

import android.os.Build
import android.os.Bundle
import android.support.v7.app.AppCompatActivity
import android.view.KeyEvent
import android.view.View
import com.alibaba.android.arouter.facade.annotation.Route
import com.lq.ecoldchain.R
import com.lq.ecoldchain.base.BaseNavigator
import com.lq.ecoldchain.util.ViewUtils

/*
*2018/12/21 0021  14:00
*登录 by lq
*/
@Route(path =BaseNavigator.login)
class LoginActivity : AppCompatActivity() {
    override fun onCreate(savedInstanceState: Bundle?) {
        super.onCreate(savedInstanceState)
        setContentView( R.layout.activity_login)
        setStatusBlackFont()
        initView()
    }

   private  fun initView() {
        supportFragmentManager.apply {
            findFragmentByTag(TAG) ?: beginTransaction()
                    .add(R.id.loginFrameLayout, LoginFragment(), TAG)
                    .commitAllowingStateLoss()
        }
    }

    private fun setStatusBlackFont() {
        if (Build.VERSION.SDK_INT >= 21) {
            val option = View.SYSTEM_UI_FLAG_LAYOUT_FULLSCREEN or View.SYSTEM_UI_FLAG_LIGHT_STATUS_BAR
            window.decorView.systemUiVisibility = option
        }
    }

    companion object {
        private const val TAG = "LoginFragment"
    }

    override fun onKeyDown(keyCode: Int, event: KeyEvent): Boolean {
        if (keyCode == KeyEvent.KEYCODE_BACK) {
            ViewUtils.exitTime(2000)
            return true
        }
        return super.onKeyDown(keyCode, event)
    }

}